<template>
  <el-dialog v-model="huan" width="500">
    <el-form :model="form">
      <el-form-item label="姓名" v-if="type == 1">
        <el-input v-model="form.names" autocomplete="off" />
      </el-form-item>
      <el-form-item label="账号" v-if="type == 1">
        <el-input v-model="form.zhanghao" autocomplete="off" />
      </el-form-item>
      <el-form-item label="重置密码" v-if="type == 1">
        <el-input v-model="form.password" autocomplete="off" />
      </el-form-item>
      <el-form-item label="班级名称" v-if="type == 2">
        <el-input v-model="form.grade" autocomplete="off" />
      </el-form-item>
      <el-form-item label="姓名" v-if="type == 3">
        <el-input v-model="form.mingzi" autocomplete="off" />
      </el-form-item>
      <el-form-item label="账号" v-if="type == 3">
        <el-input v-model="form.zhanghaos" autocomplete="off" />
      </el-form-item>
      <el-form-item label="重置密码" v-if="type == 3">
        <el-input v-model="form.passwords" autocomplete="off" />
      </el-form-item>
      <el-form-item label="真实姓名" v-if="type == 3">
        <el-input v-model="form.namess" autocomplete="off" />
      </el-form-item>
      <el-form-item label="手机号" v-if="type == 3">
        <el-input v-model="form.phone" autocomplete="off" />
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button type="primary" @click="xuigai"> 确定 </el-button>
      </div>
    </template>
  </el-dialog>
  <div></div>
</template>

<script setup>
import { inject, reactive, defineEmits, ref, watch, onMounted } from "vue";
import { setbanji, gbsz, setTeacher, banjidata } from "@/api";
import { userPiniaStore } from "@/stores";
const pian = userPiniaStore();
const huan = inject("huan");
const data = defineProps(["type"]);

watch(() => pian.banji, () => {
  if (pian.banji.id) {
    form.id = pian.banji.id
  }
})

const form = reactive({
  id: "",
  names: "",
  zhanghao: "",
  password: "",
  grade: "",
  mingzi: "",
  zhanghaos: "",
  passwords: "",
  namess: "",
  phone: "",

});

const emit = defineEmits(["close"]);
const sheshi = async () => {
  const res = await banjidata()
  emit("close", res.data.data);
};


const xuigai = async () => {
  huan.value = false;
  if (data.type == 1) {
    const res = await setbanji(form);
    // console.log(res)
    alert(res.data.msg);
  } else if (data.type == 2) {
    const res = await gbsz(form)
    // console.log(res)
    alert(res.data.msg);
    pian.setsettinbanji(res.data.data)

  } else if (data.type == 3) {
    const res = await setTeacher(form)
    console.log(res)
    alert(res.data.msg);

    pian.setsetinTeacher(res.data.data)
  }
  sheshi()

  form.names = ""
  form.zhanghao = ""
  form.password = ""
  form.grade = ""
  form.mingzi = ""
  form.zhanghaos = ""
  form.passwords = ""
  form.namess = ""
  form.phone = ""
};
</script>

<style lang="scss" scoped></style>
